package utils
{

import flash.events.Event;
import flash.text.TextField;
import flash.utils.getTimer;
	
public class FPSUtil
{ 
	private static var numFrames:Number = 0; 
	private static var interval:Number = 10 
	private static var startTime:Number;
	
	private static var currentFPS:Number = 0;
	
	private static var tf:TextField;
	
	public static function init(tf:TextField):void
	{ 
		FPSUtil.tf = tf;
		startTime = getTimer();
		tf.addEventListener(Event.ENTER_FRAME, update);
	}
	
	public static function dispose():void{
		tf.removeEventListener(Event.ENTER_FRAME, update);
	}
	
	private static function update(event:Event):void
	{ 
		if (++numFrames == interval) 
		{ 
			var now:Number = getTimer(); 
			var elapsedSeconds:Number = (now - startTime) / 1000; 
			currentFPS = numFrames / elapsedSeconds; 
			tf.text = "FPS: " + String(currentFPS.toFixed(1));
			startTime = now; 
			numFrames = 0; 
		} 
	} 
	
	
} 
}